/**
 * 功能描述
 */
define(function (require, exports, module) {
	var Grid = require("grid");
	var aw = require("ajaxwrapper");
	var Dialog = require("dialog");
	
	var roomHandler = require("../handler/roomHandler");
	
    var instance = {
        initComponent: function (params,widget) {
        	var grid = new Grid({
        		parentNode: ".J-roomtypegrid",
        		autoRender : false,
        		model:{
        			id : "roomtypegrid",
        			url : "api/signuproom/querybyreserve",
        			params : function(){
        				return {
        					pkNonMemGroupReserve : widget.get("pkNonMemGroupReserve"),
        					fetchProperties : ".*,roomType.*"
        				}
        			},
        			head : {
						items : [ {
							id : "setAll",
							type : "button",
							text : "全部落实",
							handler : function() {
								var gridData = widget.get("roomTypeGrid").getData();
								
								var flag = true;
								
								for(var i in gridData){
									if(gridData[i].roomStatus.key == "Pending"){
										flag = false;
									}
								}
								if(!flag){
									aw.ajax({
	        							url : "api/signuproom/updatestatus",
	        							data : {
	        								pkNonMemGroupReserve : widget.get("pkNonMemGroupReserve"),
	        							},
	        							dataType : "json",
	        							success : function(datas){
//	        								widget.show([".J-checkgrid"]).hide([".J-form",".J-roomtypegrid"]);
//											widget.get("subnav").hide(["return","save"]).show(["search","servicePoint","startDate","status"]);
	        								widget.get("roomTypeGrid").refresh();
	        							}
	        						})
								}else{
									Dialog.alert({
										tip : "提示",
										content : "该团所有房间都已落实！"
									});
									return false;
								}
							}
						} ]
					},
        			columns:[{
        				name:"roomType.name",
        				label:"房型",
        			},{
        				name:"count",
        				label:"数量",
        			},{
        				name:"descript",
        				label:"备注"
        			},{
        				name:"roomStatus.value",
        				label:"入住准备状态",
        			},{
        				name:"show",
        				label:"操作",
        				format:"button",
        				formatparams:[{
        					id:"Pended",
        					text:"落实",
        					show:function(value,row){
        						return !(row.roomStatus.key == "Pended");
        					},
        					handler:function(index,data,rowEL){
        						aw.ajax({
        							url : "api/signuproom/updatestatus",
        							data : {
        								pkNonMemGroupReserve : widget.get("pkNonMemGroupReserve"),
        								pkSignUpRoom : data.pkSignUpRoom
        							},
        							dataType : "json",
        							success : function(datas){
        								widget.get("roomTypeGrid").refresh();
        							}
        						})
        					}
        				}]
        			}]
        		}
        	});
        	widget.set("roomTypeGrid",grid);
        }
    };
    module.exports = instance;
});
